﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;
using System.Configuration.Install;
using System.Reflection;
namespace DynamicDnsChanger
{
    static class Program
    {
        static void Main(string[] args)
        {
            if (System.Environment.UserInteractive && args.Length > 0)
            {
                string parameter = string.Concat(args);
                Console.WriteLine("Parâmetros de linha de comando: {0}", args);
                switch (parameter)
                {
                    case "--install":
                        ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                        break;
                    case "--uninstall":
                        ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                            break;
                    case "/console":
                            new DynamicDnsChangerService().Start();
                        System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
                        break;
                    default:
                        Console.WriteLine("Nada a fazer....");
                        break;
                }
            }
            else
            {

                //Log.Debug("Criando instancias dos servicos: " + string.Concat(args, Environment.CommandLine));
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] 
                    { 
                        new DynamicDnsChangerService()    
                    };
                ServiceBase.Run(ServicesToRun);
            }
        }
    }
}
